import 'package:flutter/cupertino.dart';
import 'package:flutter_tracker/flutter_tracker.dart';
import 'package:uuid/uuid.dart';

class QwsNavigatorObserver extends NavigatorObserver {
  var uuid = const Uuid();

  @override
  void didPush(Route route, Route? previousRoute) {
    var start = DateTime.now().millisecondsSinceEpoch;
    super.didPush(route, previousRoute);
    FlutterTracker.instance.curPage = route.settings.name;
    FlutterTracker.instance.prePage = previousRoute?.settings.name;
    FlutterTracker.instance.event(
      eventId: "${route.settings.name}-page-open",
      eventType: "page",
      costTime: DateTime.now().millisecondsSinceEpoch - start,
      traceId: uuid.v4()
    ).then((value) => print(value));
    print("didPush time : ${DateTime.now().millisecondsSinceEpoch - start}");
  }

  @override
  void didPop(Route route, Route? previousRoute) {
    super.didPop(route, previousRoute);
    FlutterTracker.instance.curPage = previousRoute?.settings.name;
    FlutterTracker.instance.prePage = route.settings.name;
  }
}
